<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Список</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <style>
        .container {
            margin-top: 50px;
        }
    </style>
</head>
<body>

<nav class="navbar navbar-expand-lg bg-body-tertiary">
    <div class="container-fluid">
        <a th:href="@{/}" class="navbar-brand">TODO</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent"
                aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0"></ul>
            <form class="d-flex" role="search">
                <a th:href="@{/logout}" class="btn btn-outline-success">Выйти</a>
            </form>
        </div>
    </div>
</nav>

<div class="container">
    <div th:if="${#authorization.expression('isAuthenticated()')}">
        <h3>Список дел</h3>

        <form th:action="@{/todos/add}" th:object="${newTodo}" method="post" class="mb-3">
            <div class="input-group">
                <input type="text" th:field="*{description}" class="form-control" placeholder="Enter new todo">
                <div class="input-group-append">
                    <button type="submit" class="btn btn-primary">Добавить</button>
                </div>
            </div>
        </form>

        <table class="table">
            <thead>
            <tr>
                <th style="width: 40%">Задача</th>
                <th style="width: 20%">Создана</th>
                <th style="width: 20%">Статус</th>
                <th style="width: 40%">Действие</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="todo : ${todos}">
                <td th:text="${todo.description}"></td>
                <td th:text="${todo.date}"></td>
                <td class="text-center">
                    <span th:if="${todo.completed}" class="text-success">Готово</span>
                    <span th:unless="${todo.completed}" class="text-warning">В процессе</span>
                </td>
                <td class="text-right">
                    <form th:action="@{/todos/{id}/toggle(id=${todo.id})}" method="post" class="d-inline">
                        <button type="submit" class="btn btn-sm btn-primary">Сменить статус</button>
                    </form>
                    <form th:action="@{/todos/{id}/delete(id=${todo.id})}" method="post" class="d-inline">
                        <button type="submit" class="btn btn-sm btn-danger ml-2">Удалить</button>
                    </form>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
        crossorigin="anonymous"></script>
</body>
</html>